package com.yipei.business.controller;

import com.yipei.business.domain.Notice;
import com.yipei.business.service.INoticeService;
import com.yipei.common.annotation.Log;
import com.yipei.common.core.controller.BaseController;
import com.yipei.common.core.domain.AjaxResult;
import com.yipei.common.core.page.TableDataInfo;
import com.yipei.common.enums.BusinessType;
import com.yipei.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 通知公告Controller
 *
 * @author yipei
 * @date 2024-12-21
 */
@RestController
@RequestMapping("/business/notice")
@Api(tags = "通知公告", description = "通知公告管理")
public class NoticeController extends BaseController {
    @Autowired
    private INoticeService sysNoticeService;

    /**
     * 查询通知公告列表
     */
    //@PreAuthorize("@ss.hasPermi('business:notice:list')")
    @GetMapping("/list")
    @ApiOperation("通知公告获取数据")
    public TableDataInfo list(Notice sysNotice) {
        startPage();
        List<Notice> list = sysNoticeService.selectSysNoticeList(sysNotice);
        return getDataTable(list);
    }

    /**
     * 导出通知公告列表
     */
    //@PreAuthorize("@ss.hasPermi('business:notice:export')")
    @ApiOperation("通知公告导出数据")
    @Log(title = "通知公告", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Notice sysNotice) {
        List<Notice> list = sysNoticeService.selectSysNoticeList(sysNotice);
        ExcelUtil<Notice> util = new ExcelUtil<Notice>(Notice.class);
        util.exportExcel(response, list, "通知公告数据");
    }

    /**
     * 获取通知公告详细信息
     */
    //@PreAuthorize("@ss.hasPermi('business:notice:query')")
    @ApiOperation("通知公告通过id数据")
    @GetMapping(value = "/{noticeId}")
    public AjaxResult getInfo(@PathVariable("noticeId") Integer noticeId) {
        return success(sysNoticeService.selectSysNoticeByNoticeId(noticeId));
    }

    /**
     * 新增通知公告
     */
    //@PreAuthorize("@ss.hasPermi('business:notice:add')")
    @ApiOperation("通知公告新增数据")
    @Log(title = "通知公告", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Notice sysNotice) {
        return toAjax(sysNoticeService.insertSysNotice(sysNotice));
    }

    /**
     * 修改通知公告
     */
    //@PreAuthorize("@ss.hasPermi('business:notice:edit')")
    @ApiOperation("通知公告修改数据")
    @Log(title = "通知公告", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Notice sysNotice) {
        return toAjax(sysNoticeService.updateSysNotice(sysNotice));
    }

    /**
     * 删除通知公告
     */
    //@PreAuthorize("@ss.hasPermi('business:notice:remove')")
    @ApiOperation("通知公告删除数据")
    @Log(title = "通知公告", businessType = BusinessType.DELETE)
    @DeleteMapping("/{noticeIds}")
    public AjaxResult remove(@PathVariable Integer[] noticeIds) {
        return toAjax(sysNoticeService.deleteSysNoticeByNoticeIds(noticeIds));
    }
}
